﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _007
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //实例发布器类
            PublisherDemo e = new PublisherDemo();
            //实例订阅器类
            SubscriberDemo v = new SubscriberDemo();
            e.MyEvent += new PublisherDemo.MyEntrust(v.printf);
            e.SetValue("C#语言中文网");
            Console.ReadKey();
        }
    }
    /***************************发布器类**************************/
    public class PublisherDemo
    {
        private string value;
        public delegate void MyEntrust(string str);
        public event MyEntrust MyEvent;
        public void SetValue(string s)
        {
            value = s;
            MyEvent(value);//触发事件
        }
    }
    /***************************订阅器类**************************/
    public class SubscriberDemo
    { 
        public void printf(string str)
        {
            Console.WriteLine(str);
        }
    }

}
